package com.haiertvbic.timeline.xml.handler;

import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import com.haiertvbic.timeline.bean.ImageInfo;

public class TimeLineImageHandler extends CommContentHandler {

	private List<ImageInfo> infos = null;
	private ImageInfo imageInfo = null;
	private String tagName = "";

	@SuppressWarnings("unchecked")
	public TimeLineImageHandler() {
		super();
		this.infos = (List<ImageInfo>)mInfos;
	}

	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		String temp = new String(ch, start, length);
		if (tagName.equals("id")) {
			imageInfo.setImageId(temp);
		} else if (tagName.equals("url")) {
			imageInfo.setImageUrl(temp);
		} 
	}

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		this.tagName = qName;
		if (tagName.equals("item")) {
			imageInfo = new ImageInfo();
		}
	}
	
	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		if (qName.equals("item")) {
			infos.add(imageInfo);
		}
		tagName = "";
	}
	
}
